import java.util.Scanner;
import java.util.regex.Pattern;

public class Regular {
    public static void main(String[] args) {
        System.out.println("请输入账号");
        boolean a = true;
        while (a) {
            Scanner scan = new Scanner(System.in);
            String userIpt = scan.next();
            String regular = "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[_])[a-zA-Z0-9_]{6,20}$";//账号正则表达式
            String regylarPws = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,}$";//密码正则表达式
            String regylarEmail = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";//邮箱正则表达式
            boolean flag = Pattern.matches(regular, userIpt);//用户输入的账号进行正则的匹配
            if (flag) {//布尔值为真时输入正确进入if
                boolean f = true;//声明一个布尔用于两次输入密码一致的循环
                while (f) {
                    System.out.println("请输入密码");
                    String userPws = scan.next();
                    boolean flagPws = Pattern.matches(regylarPws, userPws);//用户输入的密码进行正则的匹配
                    if (flagPws) {//布尔值为真时输入正确进入if
                        System.out.println("再次确认密码");
                        String userPws2 = scan.next();
                        if (userPws.equals(userPws2)) {//判断两次密码一致进入if
                            boolean e = true;
                            while (e) {
                                System.out.println("请输入邮箱");
                                String userEmail = scan.next();
                                boolean flagEmail = Pattern.matches(regylarEmail, userEmail);
                                if (flagEmail) {
                                    System.out.println("注册成功");
                                    f = false;
                                    a = false;
                                    break;
                                } else {
                                    System.out.println("不符合要求重新输入");
                                }
                            }
                        } else {
                            System.out.println("两次输入不一致，请重新输入");
                        }
                    } else {
                        System.out.println("不符合要求重新输入");
                    }
                }
            } else {
                System.out.println("不符合要求重新输入");

            }
        }
    }
}
